package jp.tuyano.helo.server;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import jp.tuyano.core.PMF;
import jp.tuyano.helo.client.MyDataObject;
import jp.tuyano.helo.client.PickPDService;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class PickPDServiceImpl extends RemoteServiceServlet implements
        PickPDService {

    public List<MyDataObject> pickEntity(String condition) {
        
        PersistenceManager pm = PMF.get().getPersistenceManager();
        Query query = pm.newQuery(PersonalData.class);
        query.setFilter("name == :param");
        @SuppressWarnings("unchecked")
        List<PersonalData> pdResult =
                (List<PersonalData>) query.execute(condition);
        List<MyDataObject> mdoResult = new ArrayList<MyDataObject>();
        for (PersonalData data : pdResult) {
            mdoResult.add(new MyDataObject(data.getId(), data.getName(),
                    data.getMail(), data.getTel(),
                    data.getMemo()));
        }
        return mdoResult;
    }

}
